<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/view/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	
	<link href="${project}/ds/css//input.css" rel="stylesheet" />
	<link href="${project}/ds/css//roomStyle.css" rel="stylesheet" />
	<link href="${project}/ds/lib/layui/css/layui.css" rel="stylesheet" />
	<link href="${project}/ds/lib/ligerUI/skins/Aqua/css/ligerui-all.css"
		rel="stylesheet" />
	<link href="${project}/ds/lib/ligerUI/skins/Gray2014/css/all.css" rel="stylesheet" />
	
	<script src="${project}/ds/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
	<script src="${project}/ds/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
	<script src="${project}/ds/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
	<script src="${project}/ds/js/XHD.js" type="text/javascript"></script>
	<script src="${project}/ds/lib/layui/layui.js" type="text/javascript"></script>
	<script type="text/javascript">
	var manager;//销售代表
	var manager2;//认筹类型
	var layer;

	layui.use([ 'layer' ], function() {
		layer = layui.layer;
	});

	$(function() {
		$("#form1").ligerForm();
		manager = $("#maingrid1").ligerGrid({
			columns : [ {
				display : '序号',
				width : 50,
				render : function(rowData, rowindex) {
					return rowindex + 1;
				}
			}, {
				display : "置业顾问",
				name : "D_Name",
				width : 60
			}, {
				display : "手机",
				name : "D_Tel",
				width : 110
			} ],
			dataAction : "server",
			sortName : "D_ID",
			sortOrder : "desc",
			pageSize : 50,
			rowHeight : 22,
			pageSizeOptions : [ 20, 30, 50, 100 ],
			url : "/salesMan/getGrid",
			width : '100%',
			height : '100%',
			heightDiff : -1
		});
		manager2 = $("#maingrid2").ligerGrid({
			columns : [ {
				display : '序号',
				width : 50,
				render : function(rowData, rowindex) {
					return rowindex + 1;
				}
			}, {
				display : "认筹名称",
				name : "name",
				width : 60
			}, {
				display : "任筹金额",
				name : "money",
				width : 110
			} ],
			dataAction : "server",
			sortName : "id",
			sortOrder : "asc",
			pageSize : 50,
			rowHeight : 22,
			pageSizeOptions : [ 20, 30, 50, 100 ],
			url : "/salesMan/getRcGrid",
			width : '100%',
			height : '100%',
			heightDiff : -1
		});
	});

	function save() {
		var name = $("#name").val();
		var tel = $("#tel").val();
		if (name === "") {
			layer.msg("姓名不能为空！");
		} else if (tel === "") {
			layer.msg("手机不能为空！");
		} else if (tel.length !== 11) {
			layer.msg("手机必须为11位！");
		} else {
			$.ajax({
				url : "/salesMan/saveSalesMan",
				type : "post",
				dataType : "json",
				data : {
					name : name,
					tel : tel
				},
				success : function(data) {
					var result = data.result;
					if (result === "true") {
						layer.msg("新增成功！");
						f_reload();
						f_reset();
					} else {
						layer.msg(data.msg);
					}
				}
			});
		}
	}
	function save2() {
		var name = $("#rcname").val();
		var money = $("#money").val();
		if (name === "") {
			layer.msg("认筹名称");
		} else if (money === "") {
			layer.msg("认筹金额");
		} else {
			$.ajax({
				url : "/salesMan/saveRenChou",
				type : "post",
				dataType : "json",
				data : {
					name : name,
					money : money
				},
				success : function(data) {
					var result = data.result;
					if (result === "true") {
						layer.msg("新增成功！");
						f_reload2();
						f_reset2();
					} else {
						layer.msg(data.msg);
					}
				}
			});
		}
	}

	function del() {
		var row = manager.getSelectedRow();
		if (row) {
			layer.confirm('是否确认删除置业顾问？', function() {
				var id = row.D_ID;
				$.ajax({
					url : "/salesMan/deleteSalesMan",
					type : "post",
					data : {
						id : id
					},
					dataType : "json",
					success : function(data) {
						var result = data.result;
						if (result === "true") {
							layer.msg("删除成功");
							f_reload();
						} else {
							layer.msg(data.msg);
						}
					}
				});
			});
		} else {
			layer.msg("请选择行");
		}
	}
	function del2() {
		var row = manager2.getSelectedRow();
		if (row) {
			layer.confirm('是否确认删除认筹类型?', function() {
				var id = row.id;
				$.ajax({
					url : "/salesMan/deleteRenChou",
					type : "post",
					data : {
						id : id
					},
					dataType : "json",
					success : function(data) {
						var result = data.result;
						if (result === "true") {
							layer.msg("删除成功");
							f_reload2();
						} else {
							layer.msg(data.msg);
						}
					}
				});
			});
		} else {
			layer.msg("请选择行");
		}
	}

	function f_reload() {
		manager.loadData(true);
	}
	function f_reload2() {
		manager2.loadData(true);
	}

	function f_reset() {
		$("#name").val("");
		$("#tel").val("");
	}
	function f_reset2() {
		$("#rcname").val("");
		$("#money").val("");
	}
</script>
<style type="text/css">
.caozuo{
	float:left;
}
</style>
</head>
<body>
		<div style="margin: 10px;" class="caozuo">
			<div class="layui-inline">
				<div class="layui-input-inline">
					<input type="text" id="name" name="name" placeholder="姓名"
						class="layui-input" />
				</div>
				<div class="layui-input-inline">
					<input type="text" id="tel" name="tel" placeholder="手机"
						maxlength="11" class="layui-input" />
				</div>
			</div>
			<div class="layui-btn-group">
				<div class="layui-btn" onclick="save()">新增</div>
				<div class="layui-btn" onclick="del()">删除</div>
			</div>
		</div>
		<div style="margin: 10px;margin-left: 120px;" class="caozuo">
			<div class="layui-inline">
				<div class="layui-input-inline">
					<input type="text" id="rcname" name="rcname" placeholder="认筹名称"
						class="layui-input" />
				</div>
				<div class="layui-input-inline">
					<input type="text" id="money" name="money" placeholder="认筹金额"
						maxlength="11" class="layui-input" />
				</div>
			</div>
			<div class="layui-btn-group">
				<div class="layui-btn" onclick="save2()">新增</div>
				<div class="layui-btn" onclick="del2()">删除</div>
			</div>
		</div>
		
		<div style="height: 100%; width: 100%;">
	        <div style="left: 0px; width:39%; height: 100%; position: fixed; top:50px;">
	            <div id="maingrid1" style="margin: -1px;"></div>
	        </div>
	        <div style="left: 41%; width:59%; height: 100%; position: fixed; top:50px;">
	            <div id="maingrid2" style="margin: -1px;"></div>
	        </div>
    	</div>
</body>
</html>